/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class code1 {
    //二叉树的直径：转为二叉树的【每个节点的左右子树的高度和】和最大值
    public int ret;
    public int diameterOfBinaryTree(TreeNode root) {
        getHeight(root);
        return ret;
    }

    public int getHeight(TreeNode root) {
        if(root == null) return 0;

        int LH = getHeight(root.left);
        int LR = getHeight(root.right);

        ret = Math.max(ret,LH+LR);
        return Math.max(LH,LR)+1;
    }

}